package com.laiketui.gateway.conifg;

import com.laiketui.gateway.plugins.lang.LanguageInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;

/**
 * @description:
 * @author: wx
 * @date: Created in 2019/10/28 10:40
 * @version: 1.0
 * @modified By:
 */
@Configuration
public class TokenConfig implements WebMvcConfigurer {

    private static final Logger logger = LoggerFactory.getLogger(TokenConfig.class);

    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(
                StandardCharsets.UTF_8);
        return converter;
    }

    @Bean
    public LanguageInterceptor languageInterceptor() {
        return new LanguageInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(languageInterceptor()).addPathPatterns("/gw");
    }

}
